package authorizationAdmin

import (
	"google.golang.org/grpc"
	"grpc.getaway.adminspro.padmins.com/internal/rpc/utils/grpcServer"
	"grpc.getaway.adminspro.padmins.com/pkg/config"
	pbAuthorizationAdmin "grpc.getaway.adminspro.padmins.com/pkg/proto/authorizationAdmin"
	"strconv"
)

type auth struct {
	rpcPort         int
	rpcAddress      string
	rpcRegisterName string
}

func NewRpcServer(port int) *auth {
	return &auth{
		rpcPort:         port,
		rpcAddress:      config.Config.Rpc.Address.AuthorizationAdmin,
		rpcRegisterName: config.Config.Rpc.RegisterName.AuthorizationAdmin,
	}
}

func (rpc *auth) Run() {
	if rpc.rpcAddress == "" {
		rpc.rpcAddress = "0.0.0.0:" + strconv.Itoa(rpc.rpcPort)
	}
	grpcServer.NewServer(rpc.rpcRegisterName, rpc.rpcAddress, func(server *grpc.Server) {
		pbAuthorizationAdmin.RegisterAuthorizationAdminServer(server, rpc)
	})
}
